<!-- 搜索表单 -->
<template>
  <el-card style="width: 100%;">
    <el-form
      label-width="77px"
      class="ele-form-search"
      @keyup.enter.native="search"
      @submit.native.prevent
    >
      <el-row :gutter="24">
        <el-col :md="7" :sm="24" >
          <el-form-item label="客户名称:" >
            <el-select v-model="where.customerId" filterable clearable placeholder="请输入客户名称">
              <el-option v-for="(item, index) in customerDatas" :key="index" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24" >
          <el-form-item label="订单日期:">
            <el-date-picker v-model="where.orderDate" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="daterange"
                range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :md="5" :sm="24">
          <div class="ele-form-actions">
            <el-button
              type="primary"
              icon="el-icon-search"
              class="ele-btn-icon"
              @click="search"
            >
              查询
            </el-button>
            <el-button @click="reset">重置</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </el-card>
  </template>
  
  <script>
    const DEFAULT_WHERE = {
      keyword: '',  //关键字
      status:'',
      warehouseId:'',
      orderDate:''
    };
    import { QuerySaleOrderStatusEnum } from '@/api/enummanger';
    import { QueryCustomerPageList } from '@/api/basicdatamanager/customer';
    import { GetAllWarehouse } from '@/api/basicdatamanager/warehousemanager';
    export default {
      name: 'SaleOrderListSearch',
     
      data() {
        return {
          // 表单数据
          where: { ...DEFAULT_WHERE },
          statusEnums:[],
          customerDatas:[],
        };
      },
      //初始化数据
      created(){
       this.queryStatusEnums();
      },
  
      methods: {
  
        /* 搜索 */
        search() {
          let params = {
            pageindex: 1,
            conditions: [],
            orderBys: [{ sort: "createDate", order: 1, }],
          };
  
          //关键字查询
          if(this.where.keyword){
            params.conditions.push({
              key:"orderNo",
              operator: 1,
              value: this.where.keyword,
            });
          };

           //发货仓库
           if(this.where.warehouseId){
            params.conditions.push({
              key:"warehouseId",
              operator: 0,
              value: this.where.warehouseId,
            });
          };
  

           //订单日期
           if(this.where.orderDate){
            params.conditions.push({
              key:"orderDate",
              operator: 3,
              value:  this.where.orderDate[0] + " 00:00:00",
            });

            params.conditions.push({
              key:"orderDate",
              operator: 5,
              value:  this.where.orderDate[1] + " 23:59:59",
            });
          };
  

          //状态查询
          if(this.where.status){
            params.conditions.push({
              key:"status",
              operator: 0,
              value: this.where.status,
            });
          };
  
          this.$emit('search', params);
        },
        /*  重置 */
        reset() {
          this.where = { ...DEFAULT_WHERE };
          this.search();
        },
  
        /* 系统状态 */
        async queryStatusEnums(){
          let sysEnums = await QuerySaleOrderStatusEnum();
          sysEnums.map(e=>{
            this.statusEnums.push({Key:e.Key,Value:e.Value});
          });

          let params = {
            pageindex: 1,
            pagesize: 1000,
            conditions: [],
            orderBys: [{ sort: "createDate", order: 1, }],
          };

          let customers = await QueryCustomerPageList(params);

          if(customers){
            this.customerDatas = customers.items;
          }
        },
      }
    };
  </script>
  